package com.flashextended.apps.logomaker.view.windows.symbolpreview
{
	import com.flashextended.apps.logomaker.singleton.AppLocales;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.filters.DropShadowFilter;
	
	import mx.containers.Canvas;
	import mx.core.UIComponent;

	public class SymbolPreview extends Canvas
	{
		private var originalW:Number;
		private var originalH:Number;
		private var loader:Sprite;
		
		public function SymbolPreview(l:Sprite)
		{
			super();
			this.loader = l;
			settings();
			originalW = l.width;
			originalH = l.height;
			l.width = 30;
			l.height = 30;
			var ui:UIComponent = new UIComponent();
			ui.width = 30;
			ui.height = 30;
			ui.addChild(l);
			this.width = 50;
			this.height = 50;
			this.addChild(ui);
			ui.move(10, 10);
			this.setStyle("borderStyle", "solid");
			this.setStyle("backgroundColor", 0xFFFFFF);
			this.buttonMode = true;
			this.doubleClickEnabled = true;
			this.toolTip = AppLocales.getInstance().data.locales['selectSymbolTooltip'];
			this.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
			this.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
		}
		
		private function settings():void
		{
			this.width = 50;
			this.height = 50;
		}
		
		private function mouseOverHandler(e:MouseEvent):void
		{
			var dropShadow:DropShadowFilter = new DropShadowFilter(2, 45, 0, .3);
			this.filters = [dropShadow];
		}
		private function mouseOutHandler(e:MouseEvent):void
		{
			if(!isSelected)
			{
				this.filters = null;
			}
		}		
		
		private var _isSelected:Boolean=false;
		public function set isSelected(val:Boolean):void
		{
			_isSelected = val;
			if(val)
			{
				this.setStyle("borderColor", 0xac2d2d);
				var dropShadow:DropShadowFilter = new DropShadowFilter(2, 45, 0, .3);
				this.filters = [dropShadow];				
			}
			else
			{
				this.setStyle("borderColor", 0xCCCCCC);
				this.filters = null;
			}
		}
		public function get isSelected():Boolean
		{
			return _isSelected;
		}
		
		public function getLoader():Sprite
		{
			return loader;
		}
		
		public function getOriginalW():Number
		{
			return originalW;
		}
		public function getOriginalH():Number
		{
			return originalH;
		}		
		
	}
}